<template>
  <div>
    <BasicTable @register="registerTable">
<!--      <template #toolbar>-->
<!--        <a-button type="primary" @click="handleCreate"> 新增 </a-button>-->
<!--      </template>-->
<!--      <template #action="{ record }">-->
<!--        <TableAction-->
<!--            :actions="[-->
<!--            {-->
<!--              icon: 'clarity:note-edit-line',-->
<!--              onClick: handleEdit.bind(null, record),-->
<!--            },-->
<!--            {-->
<!--              icon: 'ant-design:delete-outlined',-->
<!--              color: 'error',-->
<!--              popConfirm: {-->
<!--                title: '是否确认删除',-->
<!--                confirm: handleDelete.bind(null, record),-->
<!--              },-->
<!--            },-->
<!--          ]"-->
<!--        />-->
<!--      </template>-->
    </BasicTable>
    <SysSmsRecordModal @register="registerModal" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicUpload } from '/@/components/Upload';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getSysSmsRecordList, deleteSysSmsRecord } from '/@/api/sys/smsRecord';
  import { useModal } from '/@/components/Modal';
  import SysSmsRecordModal from './SysSmsRecordModal.vue';
  import { columns, searchFormSchema } from './sms.data';
  import {useMessage} from "/@/hooks/web/useMessage";
  export default defineComponent({
    name: 'SysSmsRecordManagement',
    components: { BasicTable, SysSmsRecordModal, TableAction, BasicUpload },
    setup() {
      const [registerModal, { openModal }] = useModal();
      const { createMessage } = useMessage();
      const [registerTable, { reload }] = useTable({
        title: '短信发送记录列表',
        api: getSysSmsRecordList,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        pagination: true,
        striped: false,
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        canResize: false,
        actionColumn: {
          width: 150,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
      });

      function handleCreate() {
        openModal(true, {
          isUpdate: false,
        });
      }
      function handleEdit(record: Recordable) {
        openModal(true, {
          record,
          isUpdate: true,
        });
      }

      async function handleDelete(record: Recordable) {
        await deleteSysSmsRecord(record.id);
        createMessage.success('操作成功');
        await reload();
      }
      function handleSuccess() {
        createMessage.success('操作成功');
        reload();
      }
      return {
        registerTable,
        registerModal,
        handleCreate,
        handleEdit,
        handleDelete,
        handleSuccess
      };
    },
  });
</script>
